﻿namespace Centido.Core.Test
{
    using System;
    using System.Linq;

    /// <summary>
    /// Testing string properties
    /// </summary>
    internal static class StringProperty
    {
        /// <summary>
        /// Maximum length of standard string column
        /// </summary>
        public const int StandardStringColumnLength = 255;

        /// <summary>
        /// Maximum length of extended string column
        /// </summary>
        public const int ExtendedStringColumnLength = 1000;

        /// <summary>
        /// Generate string property value
        /// </summary>
        /// <param name="repeatedCharatacter">Repeated character</param>
        /// <param name="repetitionCount">Repetition number</param>
        /// <returns></returns>
        public static string Value(char repeatedCharatacter, int repetitionCount)
        {
            return new string(Enumerable.Repeat(repeatedCharatacter, repetitionCount).ToArray());
        }

        /// <summary>
        /// Generate identifier with standard length
        /// </summary>
        /// <param name="repeatedCharacter">Repeated character</param>
        /// <returns></returns>
        public static string Identifier(char repeatedCharacter)
        {
            return Value(repeatedCharacter, DbRule.IdentifierMaxLength);
        }

        /// <summary>
        /// Generate random identifier
        /// </summary>
        /// <returns></returns>
        public static string RandomIdentifier()
        {
            //Upper case is used on purpose. It allows to check the lowering of object names
            return "A" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 25).ToUpper();
        }

        /// <summary>
        /// Generate random password
        /// </summary>
        /// <returns></returns>
        public static string RandomPassword()
        {
            return "9A#_" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 25);
        }

        /// <summary>
        /// Generate string property value with standard length
        /// </summary>
        /// <param name="repeatedCharacter">Repeated character</param>
        /// <returns></returns>
        public static string StandardValue(char repeatedCharacter)
        {
            return Value(repeatedCharacter, StandardStringColumnLength);
        }

        /// <summary>
        /// Generate string property value with standard length
        /// </summary>
        /// <param name="repeatedCharacter">Repeated character</param>
        /// <returns></returns>
        public static string ExtendedValue(char repeatedCharacter)
        {
            return Value(repeatedCharacter, ExtendedStringColumnLength);
        }

        /// <summary>
        /// Generate identifier with too long length
        /// </summary>
        /// <param name="repeatedCharacter">Repeated character</param>
        /// <returns></returns>
        public static string TooLongIdentifier(char repeatedCharacter)
        {
            return Value(repeatedCharacter, DbRule.IdentifierMaxLength + 1);
        }

        /// <summary>
        /// Generate string property value with too long length
        /// </summary>
        /// <param name="repeatedCharacter">Repeated character</param>
        /// <returns></returns>
        public static string TooLongStandardValue(char repeatedCharacter)
        {
            return Value(repeatedCharacter, StandardStringColumnLength + 1);
        }

        /// <summary>
        /// Generate string property value with too long length
        /// </summary>
        /// <param name="repeatedCharacter">Repeated character</param>
        /// <returns></returns>
        public static string TooLongExtendedValue(char repeatedCharacter)
        {
            return Value(repeatedCharacter, ExtendedStringColumnLength + 1);
        }
    }
}